home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / misc / emu / flamingo.lha / Flamingo / sources / ecs.asm < prev    next >
Encoding:
Assembly Source File  |  1999-07-13  |  11.3 KB  |  599 lines

  1. ; ECS
  2. ; External Video Driver for
  3. ; Flaming Plus/4 emulator for the Amiga
  4. ;
  5. ; version 1.1
  6.  
  7.     MACHINE    68020
  8.  
  9.         INCDIR    Include:
  10.  
  11.     INCLUDE exec/types.i
  12.     INCLUDE    exec/memory.i
  13.     INCLUDE    exec/exec_lib.i
  14.     INCLUDE    utility/tagitem.i
  15.     INCLUDE    intuition/intuition.i
  16.     INCLUDE    intuition/intuition_lib.i
  17.     INCLUDE    intuition/screens.i
  18.     INCLUDE    graphics/graphics_lib.i
  19.     INCLUDE graphics/modeid.i
  20.     INCLUDE    graphics/rastport.i
  21.     INCLUDE    dos/dos.i
  22.     INCLUDE    dos/dos_lib.i
  23.     INCLUDE    libraries/asl.i
  24.     INCLUDE    libraries/asl_lib.i
  25.     INCLUDE    macros.i
  26.  
  27. ;*** Handler structure
  28.  
  29.  STRUCTURE vxd_handler,0
  30.   LONG intuibase
  31.   LONG graphbase
  32.   LONG dosbase
  33.   LONG aslbase
  34.   LONG myscr
  35.   LONG mywin
  36.   LONG planes
  37.   WORD xsize
  38.   WORD ysize
  39.   LONG emuscr
  40.   LONG scrmodereq
  41.   LONG screendim
  42.   WORD bytesperrow
  43.  LABEL    vxd_handler_SIZEOF
  44.  
  45.  STRUCTURE c2p,4
  46.   LONG C2PChunkyBufferAddress
  47.   LONG C2PPlanarBufferAddress
  48.   LONG C2PChunkyBufferWidth
  49.   LONG C2PChunkyBufferHeight
  50.   LONG C2PBitplaneByteWidth
  51.  LABEL c2p_SIZEOF
  52.  
  53. JSRLIB    MACRO
  54.     jsr    _LVO\1(a6)
  55.     ENDM
  56.  
  57. ;*** Let's begin
  58.  
  59.     moveq.l    #0,d0
  60.     rts
  61.  
  62.     dc.b "FLAMINGOXVD"
  63.     dc.b "1"
  64.  
  65.     dc.l Name
  66.     dc.l Author
  67.     dc.w 1
  68.     dc.w 1
  69.  
  70.     dc.l drv_Init
  71.     dc.l drv_Done
  72.     dc.l drv_Configure
  73.     dc.l drv_OpenScreen
  74.     dc.l drv_CloseScreen
  75.     dc.l drv_Refresh
  76.  
  77. Name:    dc.b    "ECS External Video Driver",0
  78. Author:    dc.b    "Álmos Rajnai (original C2P by Ferenc Zavacki)",0
  79.  
  80.     EVEN
  81.  
  82. ;*** Functions
  83.  
  84. drv_Init:
  85.     movem.l    a0-a1,-(sp)    ;Saving infos
  86.     move.l  4.w,a6        ;Alloc memory for handler
  87.     move.l    #MEMF_PUBLIC|MEMF_CLEAR,d1
  88.     move.l    #vxd_handler_SIZEOF,d0
  89.     JSRLIB    AllocVec
  90.     movem.l    (sp)+,a0-a1    ;Recover infos
  91.         tst.l    d0
  92.     beq.b    .1        ;No mem
  93.     movea.l    d0,a2
  94.         move.l    (a0),graphbase(a2)    ;Saving graphics.library base
  95.         move.l    4(a0),dosbase(a2)    ;Saving dos.library base
  96.         move.l    8(a0),intuibase(a2)    ;Saving intuition.library base
  97.         move.l    16(a0),aslbase(a2)    ;Saving asl.library base
  98.         movem.l    d0,-(sp)
  99.  
  100.     move.l    dosbase(a2),a6        ;Reading config file
  101.     move.l    #configfile,d1        ;Config file is pretty simple:
  102.     move.l    #MODE_OLDFILE,d2    ;only a screenmode number
  103.     JSRLIB    Open
  104.     tst.l    d0
  105.     beq.b    .2            ;Failed open
  106.     move.l    d0,d1
  107.     move.l    (sp),a0
  108.     lea    screendim(a0),a0
  109.     move.l    a0,d2
  110.     moveq.l    #4,d3
  111.     movem.l    d0,-(sp)
  112.     JSRLIB    Read            ;Reading the 4 bytes
  113.     cmp.l    #4,d0
  114.     beq.b    .3
  115.     move.l    (sp),a0            ;Failed: set 0 instead garbage
  116.     move.l    #0,screendim(a0)
  117.  
  118. .3    movem.l    (sp)+,d1
  119.     JSRLIB    Close
  120.  
  121. .2    movem.l    (sp)+,d0
  122. .1    move.l    #err_nomem,d1        ;Ignored, if D0 not 0
  123.     rts                ;Result in D0 available for now
  124.  
  125. drv_Done:
  126.     movea.l    a0,a1
  127.     cmpa.l    #0,a1
  128.     beq.b    .1
  129.     move.l    4.w,a6
  130.     JSRLIB    FreeVec        ;Deallocate handler
  131. .1
  132.     rts
  133.  
  134. drv_Configure:            ;Configure
  135.                 ;A simple screenmode requester appears
  136.     movem.l    a0,-(sp)
  137.     move.l    screendim(a0),displayid
  138.     move.l    #ASL_ScreenModeRequest,d0    
  139.     move.l    aslbase(a0),a6
  140.     lea    asltags,a0
  141.     JSRLIB    AllocAslRequest
  142.     move.l    (sp),a0
  143.     move.l    d0,scrmodereq(a0)
  144.     tst.l    d0
  145.     bne.b    config2
  146.     lea    4(sp),sp
  147.     rts
  148.  
  149. config2:
  150.     move.l    d0,a0
  151.     suba.l    a1,a1
  152.     JSRLIB    AslRequest
  153.     tst.l    d0
  154.     beq.b    .1
  155.  
  156.     move.l    (sp),a1
  157.     move.l    scrmodereq(a1),a0
  158.     move.l    sm_DisplayID(a0),screendim(a1)
  159.  
  160.     move.l    dosbase(a1),a6        ;Writing config file
  161.     move.l    #configfile,d1        ;Config file is pretty simple:
  162.     move.l    #MODE_NEWFILE,d2    ;only a screenmode number
  163.     JSRLIB    Open
  164.     tst.l    d0
  165.     beq.b    .1            ;Failed open
  166.     move.l    d0,d1
  167.     move.l    (sp),a0
  168.     lea    screendim(a0),a0
  169.     move.l    a0,d2
  170.     moveq.l    #4,d3
  171.     movem.l    d0,-(sp)
  172.     JSRLIB    Write            ;Writing the 4 bytes
  173.  
  174.     movem.l    (sp)+,d1        ;We don't care too much on
  175.     JSRLIB    Close            ;success...
  176.  
  177. .1    movem.l    (sp)+,a0
  178.     move.l    aslbase(a0),a6
  179.     move.l    scrmodereq(a0),a0
  180.     JSRLIB    FreeAslRequest
  181.     rts
  182.  
  183. drv_OpenScreen:
  184.     movea.l a0,a5
  185.     move.w    (a1)+,xsize(a5)
  186.     move.w    (a1)+,ysize(a5)
  187.     move.l    screendim(a5),screenmode    ;screenmode from init
  188.  
  189.     moveq.l    #0,d0
  190.     move.l    d0,d1
  191.     move.w    xsize(a5),d0
  192.     move.w    ysize(a5),d1
  193.     mulu.w    d1,d0
  194.     move.l    #MEMF_PUBLIC|MEMF_CLEAR,d1
  195.     move.l    4.w,a6
  196.     JSRLIB    AllocVec
  197.     move.l    d0,emuscr(a5)        ;allocating emulator screen
  198.     beq.w    .1
  199.  
  200.     move.w    xsize(a5),width+2
  201.     move.w    ysize(a5),height+2
  202.         suba.l    a0,a0            ;No newscreen stuct
  203.         lea    scrtags,a1
  204.     movea.l    intuibase(a5),a6
  205.     JSRLIB    OpenScreenTagList
  206.     move.l    d0,myscr(a5)
  207.     beq.w    .1
  208.     move.l    d0,wscr
  209.     move.l    d0,a0
  210.     lea    sc_RastPort(a0),a0
  211.     movea.l    rp_BitMap(a0),a0
  212.     move.l    #BMA_FLAGS,d1
  213.     movea.l    graphbase(a5),a6
  214.     JSRLIB    GetBitMapAttr
  215.     and.l    #BMF_STANDARD|BMF_INTERLEAVED,d0
  216.     cmp.l    #BMF_STANDARD|BMF_INTERLEAVED,d0
  217.     beq.b    .3
  218.     movea.l    intuibase(a5),a6
  219.     move.l    myscr(a5),a0
  220.     JSRLIB    CloseScreen
  221.     moveq.l    #0,d0
  222.     move.l    d0,myscr(a5)
  223.     bra.b    .1
  224.  
  225. .3    move.w    xsize(a5),wwidth+2
  226.     move.w    ysize(a5),wheight+2
  227.     suba.l    a0,a0
  228.     lea    wintags,a1
  229.     movea.l    intuibase(a5),a6
  230.     JSRLIB    OpenWindowTagList
  231.     move.l    d0,mywin(a5)
  232.     beq.b    .1
  233.     movea.l    d0,a1
  234.     move.l  wd_RPort(a1),a0
  235.     move.l    rp_BitMap(a0),a0
  236.     move.l    bm_Planes(a0),planes(a5)
  237.     move.w    bm_BytesPerRow(a0),d0
  238.     and.l    #$ffff,d0
  239.     moveq.l    #3,d1
  240.     divu.w    d1,d0
  241.     move.w    d0,bytesperrow(a5)
  242.     move.l  wd_UserPort(a1),d0    ;IDCMP port
  243.     move.l    emuscr(a5),d2        ;chunky buffer
  244.  
  245. .1    move.l    #err_noscr,d1
  246.     moveq.l    #0,d3            ;no chunky modulo
  247.     rts
  248.  
  249. drv_CloseScreen:
  250.     move.l    a0,a5
  251.     move.l    intuibase(a5),a6
  252.     move.l    mywin(a5),a0
  253.     cmpa.l    #0,a0
  254.     beq.b    .1
  255.     JSRLIB    CloseWindow
  256.  
  257. .1    move.l    myscr(a5),a0
  258.     cmpa.l    #0,a0
  259.     beq.b    .2
  260.     JSRLIB    CloseScreen
  261.  
  262. .2    movea.l    emuscr(a5),a1
  263.         cmpa.l    #0,a1
  264.     beq.b    .3
  265.     move.l    4.w,a6
  266.     JSRLIB    FreeVec        ;Deallocate translated palette
  267.  
  268. .3    moveq.l    #0,d0
  269.     move.l    d0,emuscr(a5)    ;They were already freed
  270.     move.l    d0,myscr(a5)
  271.     move.l    d0,mywin(a5)
  272.  
  273.     rts
  274.  
  275. drv_Refresh:
  276.     SUBA.L    #c2p_SIZEOF,A7        ;Storing all data on stack
  277.  
  278.     MOVE.L    (emuscr,A0),(C2PChunkyBufferAddress,A7)
  279.     MOVE.L    (planes,A0),(C2PPlanarBufferAddress,A7)
  280.     MOVEQ.L    #0,D0
  281.     MOVE.W    (xsize,A0),D0
  282.     MOVE.L    D0,(C2PChunkyBufferWidth,A7)
  283.     MOVE.W    (ysize,A0),D0
  284.     MOVE.L    D0,(C2PChunkyBufferHeight,A7)
  285.     MOVE.W    (bytesperrow,A0),D0
  286.     MOVE.L    D0,(C2PBitplaneByteWidth,A7)
  287.  
  288.  
  289.         MOVE.L  (C2PChunkyBufferAddress,A7),A0
  290.         MOVE.L  (C2PChunkyBufferWidth,A7),D0
  291.         MULU.L  (C2PChunkyBufferHeight,A7),D0
  292.         LEA     (A0,D0.L),A2
  293.  
  294.         MOVE.L  (C2PPlanarBufferAddress,A7),A1
  295.  
  296.         MOVE.L  (C2PChunkyBufferWidth,A7),D6
  297.         LSR.L   #5,D6
  298.  
  299.         MOVE.L  (C2PBitplaneByteWidth,A7),D7
  300.  
  301.         MOVE.L  #$70707070,D5
  302.  
  303.         MOVE.L  (A0)+,D0
  304.         AND.L   D5,D0
  305.         MOVE.L  (A0)+,D1
  306.         AND.L   D5,D1
  307.         LSR.L   #4,D1
  308.         OR.L    D1,D0
  309.  
  310.         MOVE.L  (A0)+,D1
  311.         AND.L   D5,D1
  312.         MOVE.L  (A0)+,D2
  313.         AND.L   D5,D2
  314.         LSR.L   #4,D2
  315.         OR.L    D2,D1
  316.  
  317.         MOVE.L  (A0)+,D2
  318.         AND.L   D5,D2
  319.         MOVE.L  (A0)+,D3
  320.         AND.L   D5,D3
  321.         LSR.L   #4,D3
  322.         OR.L    D3,D2
  323.  
  324.         MOVE.L  (A0)+,D3
  325.         AND.L   D5,D3
  326.         MOVE.L  (A0)+,D4
  327.         AND.L   D5,D4
  328.         LSR.L   #4,D4
  329.         OR.L    D4,D3
  330.  
  331.         MOVE.W  D2,D4
  332.         MOVE.W  D0,D2
  333.         SWAP    D2
  334.         MOVE.W  D2,D0
  335.         MOVE.W  D4,D2
  336.  
  337.         MOVE.W  D3,D4
  338.         MOVE.W  D1,D3
  339.         SWAP    D3
  340.         MOVE.W  D3,D1
  341.         MOVE.W  D4,D3
  342.  
  343.         MOVE.L  #$00FF00FF,D5
  344.  
  345.         MOVE.L  D1,D4
  346.         LSR.L   #8,D4
  347.         EOR.L   D0,D4
  348.         AND.L   D5,D4
  349.         EOR.L   D4,D0
  350.         LSL.L   #8,D4
  351.         EOR.L   D4,D1
  352.  
  353.         MOVE.L  D3,D4
  354.         LSR.L   #8,D4
  355.         EOR.L   D2,D4
  356.         AND.L   D5,D4
  357.         EOR.L   D4,D2
  358.         LSL.L   #8,D4
  359.         EOR.L   D4,D3
  360.  
  361.         MOVE.L  #$33333333,D5
  362.  
  363.         MOVE.L  D2,D4
  364.         LSR.L   #2,D4
  365.         EOR.L   D0,D4
  366.         AND.L   D5,D4
  367.         EOR.L   D4,D0
  368.         LSL.L   #2,D4
  369.         EOR.L   D4,D2
  370.  
  371.         MOVE.L  D3,D4
  372.         LSR.L   #2,D4
  373.         EOR.L   D1,D4
  374.         AND.L   D5,D4
  375.         EOR.L   D4,D1
  376.         LSL.L   #2,D4
  377.         EOR.L   D4,D3
  378.  
  379.         MOVE.L  #$55555555,D5
  380.  
  381.         MOVE.L  D1,D4
  382.         LSR.L   #1,D4
  383.         EOR.L   D0,D4
  384.         AND.L   D5,D4
  385.         EOR.L   D4,D0
  386.         LSL.L   #1,D4
  387.         EOR.L   D4,D1
  388.  
  389.         MOVE.L  D3,D4
  390.         LSR.L   #1,D4
  391.         EOR.L   D2,D4
  392.         AND.L   D5,D4
  393.         EOR.L   D4,D2
  394.         LSL.L   #1,D4
  395.         EOR.L   D4,D3
  396.  
  397.         MOVE.L  D0,A3
  398.         MOVE.L  D1,A4
  399.         MOVE.L  D2,A5
  400.         MOVE.L  D3,A6
  401.  
  402. .1      MOVE.L  #$70707070,D5
  403.  
  404.         MOVE.L  (A0)+,D0
  405.         AND.L   D5,D0
  406.         MOVE.L  (A0)+,D1
  407.         AND.L   D5,D1
  408.         LSR.L   #4,D1
  409.         OR.L    D1,D0
  410.  
  411.         MOVE.L  (A0)+,D1
  412.         AND.L   D5,D1
  413.         MOVE.L  (A0)+,D2
  414.         AND.L   D5,D2
  415.         LSR.L   #4,D2
  416.         OR.L    D2,D1
  417.  
  418.         MOVE.L  (A0)+,D2
  419.         AND.L   D5,D2
  420.         MOVE.L  (A0)+,D3
  421.         AND.L   D5,D3
  422.         LSR.L   #4,D3
  423.         OR.L    D3,D2
  424.  
  425.         MOVE.L  (A0)+,D3
  426.         AND.L   D5,D3
  427.         MOVE.L  (A0)+,D4
  428.         AND.L   D5,D4
  429.         LSR.L   #4,D4
  430.         OR.L    D4,D3
  431.  
  432.         MOVE.L  A6,(A1)+
  433.  
  434.         MOVE.W  D2,D4
  435.         MOVE.W  D0,D2
  436.         SWAP    D2
  437.         MOVE.W  D2,D0
  438.         MOVE.W  D4,D2
  439.  
  440.         MOVE.W  D3,D4
  441.         MOVE.W  D1,D3
  442.         SWAP    D3
  443.         MOVE.W  D3,D1
  444.         MOVE.W  D4,D3
  445.  
  446.         MOVE.L  #$00FF00FF,D5
  447.  
  448.         MOVE.L  D1,D4
  449.         LSR.L   #8,D4
  450.         EOR.L   D0,D4
  451.         AND.L   D5,D4
  452.         EOR.L   D4,D0
  453.         LSL.L   #8,D4
  454.         EOR.L   D4,D1
  455.  
  456.         MOVE.L  A5,(-4,A1,D7.L)
  457.  
  458.         MOVE.L  D3,D4
  459.         LSR.L   #8,D4
  460.         EOR.L   D2,D4
  461.         AND.L   D5,D4
  462.         EOR.L   D4,D2
  463.         LSL.L   #8,D4
  464.         EOR.L   D4,D3
  465.  
  466.         MOVE.L  #$33333333,D5
  467.  
  468.         MOVE.L  D2,D4
  469.         LSR.L   #2,D4
  470.         EOR.L   D0,D4
  471.         AND.L   D5,D4
  472.         EOR.L   D4,D0
  473.         LSL.L   #2,D4
  474.         EOR.L   D4,D2
  475.  
  476.         MOVE.L  A4,(-4,A1,D7.L*2)
  477.  
  478.         MOVE.L  D3,D4
  479.         LSR.L   #2,D4
  480.         EOR.L   D1,D4
  481.         AND.L   D5,D4
  482.         EOR.L   D4,D1
  483.         LSL.L   #2,D4
  484.         EOR.L   D4,D3
  485.  
  486.         MOVE.L  #$55555555,D5
  487.  
  488.         MOVE.L  D1,D4
  489.         LSR.L   #1,D4
  490.         EOR.L   D0,D4
  491.         AND.L   D5,D4
  492.         EOR.L   D4,D0
  493.         LSL.L   #1,D4
  494.         EOR.L   D4,D1
  495.  
  496.         MOVE.L  D3,D4
  497.         LSR.L   #1,D4
  498.         EOR.L   D2,D4
  499.         AND.L   D5,D4
  500.         EOR.L   D4,D2
  501.         LSL.L   #1,D4
  502.         EOR.L   D4,D3
  503.  
  504.         MOVE.L  D0,A3
  505.         MOVE.L  D1,A4
  506.         MOVE.L  D2,A5
  507.         MOVE.L  D3,A6
  508.  
  509.         SUBQ.L   #1,D6
  510.         BNE.B   .2
  511.  
  512.         MOVE.L  (C2PChunkyBufferWidth,A7),D6
  513.         LSR.L   #3,D6
  514.         SUB.L   D6,A1
  515.         LSR.L   #2,D6
  516.         LEA     (A1,D7.L*4),A1
  517.     SUBA.L    D7,A1
  518.  
  519. .2      CMP.L   A2,A0
  520.         BNE     .1
  521.  
  522.     MOVE.L    C2PChunkyBufferAddress(A7),D0    ;giving back chunky buffer
  523.         ADDA.L    #c2p_SIZEOF,A7
  524.     
  525.         RTS
  526.  
  527.     EVEN
  528.  
  529. ;*** Constants
  530.  
  531. scrtags:
  532.     dc.l    SA_Width
  533. width:    dc.l    0
  534.     dc.l    SA_Height
  535. height:    dc.l    0
  536.     dc.l    SA_Depth,3
  537.     dc.l    SA_Colors32,palette32
  538.     dc.l    SA_Title,scrtitle
  539.     dc.l    SA_ShowTitle,FALSE
  540.     dc.l    SA_DisplayID
  541. screenmode:
  542.     dc.l    0
  543.     dc.l    SA_Interleaved,TRUE
  544.     dc.l    SA_Type,CUSTOMSCREEN
  545.     dc.l    SA_AutoScroll,TRUE
  546.     dc.l    SA_Overscan,OSCAN_STANDARD
  547.     dc.l    SA_Quiet,TRUE
  548.     dc.l    TAG_DONE
  549.  
  550. wintags:
  551.     dc.l    WA_Left,0
  552.     dc.l    WA_Top,0
  553.     dc.l    WA_Width
  554. wwidth:    dc.l    0
  555.     dc.l    WA_Height
  556. wheight:    dc.l    0
  557.     dc.l    WA_IDCMP,IDCMP_RAWKEY
  558.     dc.l    WA_Title,0
  559.     dc.l    WA_Backdrop,TRUE
  560.     dc.l    WA_RMBTrap,TRUE
  561.     dc.l    WA_Borderless,TRUE
  562.     dc.l    WA_NoCareRefresh,TRUE
  563.     dc.l    WA_CustomScreen
  564. wscr:    dc.l    0
  565.     dc.l    WA_SimpleRefresh,TRUE
  566.     dc.l    WA_Activate,TRUE
  567.     dc.l    TAG_DONE
  568.  
  569. asltags:
  570.     dc.l    ASLSM_TitleText,configwintxt
  571.     dc.l    ASLSM_InitialDisplayID
  572. displayid:
  573.     dc.l    0
  574.     dc.l    TAG_DONE
  575.  
  576. palette32:
  577.     dc.w    8,0
  578.  
  579. offs    SET    $30
  580.     REPT    8
  581.     dc.l    offs<<24,offs<<24,offs<<24
  582. offs    SET    offs+$1a
  583.     ENDR
  584.     dc.l    0,0,0,0
  585.  
  586. scrtitle:    dc.b    'Flamingo Plus/4 emulator screen',0
  587.  
  588. configwintxt:    dc.b    'Choose desired screenmode',0
  589.  
  590. configfile:    dc.b    'ecs.cfg',0
  591.  
  592. ;*** Errors
  593.  
  594. err_nomem:
  595.     dc.b    'Run out of memory',0
  596. err_noscr:
  597.     dc.b    'Cannot open screen',0
  598.  
  599.